<?php
include_once APPLICATION_PATH."/models/base/Area_Province_CategoryBase.php";
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
class Model_Area_Province_Category extends Model_Area_Province_CategoryBase{
    
}
class Model_Area_Province_CategoryMapper extends Model_Area_Province_CategoryMapperBase{
    public static function GetAreaProvince(){
        $db = Zend_Db_Table::getDefaultAdapter();
        $select= 'select IFNULL(area_province_category.id,0) as id,area.id as area_id,IFNULL(area_province_category.province_id,0) as province_id from area left join area_province_category on area.id = area_province_category.area_id';
        $stmt=$db->query($select);
        $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $entries   = array();
        foreach ($rows as $row){
            $entry = new Model_Area_Province_Category();
            $entry->setId($row->id)
                ->setId($row->id)
                ->setProvince_Id($row->province_id)
                ->setArea_Id($row->area_id);
             $entries[] = $entry;
        }
        return $entries;
    }
    public static function findareaidbyprovinceid($province_id){
        $db = Zend_Db_Table::getDefaultAdapter();
        $select= "select area_id from area_province_category where province_id='$province_id'";
        $stmt=$db->query($select);
        $row = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        if($row==NULL){
            return null;
        }
        return $row[0]->area_id;   
    }
}
